package org.visionlibrary.image.filters.geometric;

import javax.media.jai.TiledImage;

import org.visionlibrary.image.acquisition.ImageFactory;
import org.visionlibrary.image.model.AbstractFilter;


public class VerticalMirror extends AbstractFilter {
	public TiledImage applyFilter(TiledImage src, TiledImage dest) {
		if (null == src)
			throw new NullPointerException("Source image is null.");

		if (null == dest)
			dest = (new ImageFactory()).createCompatibleImage(src);
		
		int maxX = src.getWidth();
		int maxY = src.getHeight();
		for (int ch = 0; ch < src.getNumBands(); ch++)
			for (int x = 0; x < maxX / 2; x++)
				for (int y = 0; y < maxY; y++) {
					int left = src.getSample(x, y, ch);
					int right = src.getSample(maxX - x - 1, y, ch);
					dest.setSample(x, y, ch, right);
					dest.setSample(maxX - x - 1, y, ch, left);
				}

		return dest;
	}

}
